package com.ruoyi.ruoyiyinzheng.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.ruoyiyinzheng.domain.vo.StTestVo;
import com.ruoyi.ruoyiyinzheng.domain.bo.StTestBo;
import com.ruoyi.ruoyiyinzheng.service.IStTestService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试格控制器
 * 前端访问路由地址为:/ruoyiyinzheng/ruoyiyinzheng
 *
 * @author cody
 * @date 2023-09-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ruoyiyinzheng")
public class StTestController extends BaseController {

    private final IStTestService iStTestService;

    /**
     * 查询测试格列表
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:list")
    @GetMapping("/list")
    public TableDataInfo<StTestVo> list(StTestBo bo, PageQuery pageQuery) {
        return iStTestService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出测试格列表
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:export")
    @Log(title = "测试格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StTestBo bo, HttpServletResponse response) {
        List<StTestVo> list = iStTestService.queryList(bo);
        ExcelUtil.exportExcel(list, "测试格", StTestVo.class, response);
    }

    /**
     * 获取测试格详细信息
     *
     * @param testId 主键
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:query")
    @GetMapping("/{testId}")
    public R<StTestVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long testId) {
        return R.ok(iStTestService.queryById(testId));
    }

    /**
     * 新增测试格
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:add")
    @Log(title = "测试格", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StTestBo bo) {
        return toAjax(iStTestService.insertByBo(bo));
    }

    /**
     * 修改测试格
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:edit")
    @Log(title = "测试格", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StTestBo bo) {
        return toAjax(iStTestService.updateByBo(bo));
    }

    /**
     * 删除测试格
     *
     * @param testIds 主键串
     */
    @SaCheckPermission("ruoyiyinzheng:ruoyiyinzheng:remove")
    @Log(title = "测试格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{testIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] testIds) {
        return toAjax(iStTestService.deleteWithValidByIds(Arrays.asList(testIds), true));
    }
}
